
const path = require('path')
const fs = require('fs')

const { defineConfig, build } = require('vite');
const vue = require('@vitejs/plugin-vue');
const vueJsx = require('@vitejs/plugin-vue-jsx');

const entryDir = path.resolve(__dirname, '../packages/widgets')
const outputDir = path.resolve(__dirname, './build')

const baseConfig = defineConfig({
  configFile: false,
  publicDir: false,
  plugins: [vue(), vueJsx()]
})

const rollupOptions = {
  external: ['vue', '@vueuse/core']
}

const buildAll = async () => {
  await build(
    defineConfig({
      ...baseConfig,
      build: {
        rollupOptions,
        lib: {
          entry: path.resolve(entryDir, 'index.js'),
          name: 'DiitWidgets',
          fileName: 'diit-widgets',
          formats: ['es', 'umd']
        },
        outDir: outputDir
      }
    })
  )
  console.log('打包完成')
}

buildAll()
